# -*- coding: utf-8 -*-

from qiniu import Auth, put_file, etag, urlsafe_base64_encode
import os

access_key='FOIS0CQVt3uVs1nihatVxCY0WJaESXnCP8bmmjoT'
secret_key='TijwIPc574XOsEOlLVSyCnzdrI4AxQKB_WDwhzjz'

#需要上传的文件filename
def upload(filename):
    #构建鉴权对象
    q = Auth(access_key, secret_key)
    #要上传的空间
    bucket_name = 'spitemoji'
    key = os.path.basename(filename)
    #生成上传 Token，可以指定过期时间等
    token = q.upload_token(bucket_name, key, 3600)
    #要上传文件的本地路径
    ret, info = put_file(token, key, filename)
    assert ret['key'] == key
    assert ret['hash'] == etag(filename)
    return info
